package cn.cgg.demo;

import cn.cgg.Constants;
import lombok.Builder;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

public class Producer {
    public static void main(String[] args) throws Exception {
        //创建生产者数组
        DefaultMQProducer producer = new DefaultMQProducer("hello-world");
        //设置nameserver地址
        producer.setNamesrvAddr(Constants.NAME_SERVER_URL);
        //启动product实例
        producer.start();
        //创建消息
        Message message = new Message("log-topic", "info_tag", "谌媾觏脑壳真大".getBytes(RemotingHelper.DEFAULT_CHARSET));//防止中文乱码
        //发送消息
        SendResult result = producer.send(message);
        //关闭product
        System.out.println("发送完毕,结果:"+result);
        producer.shutdown();
    }
}
